package com.zlt.dao.Impl;

import com.zlt.dao.DeliveryDao;
import com.zlt.entity.*;
import com.zlt.util.JDBCUtil;
import com.zlt.util.SqlUtil;
import com.zlt.vo.DeliveryVO;
import com.zlt.vo.Pager;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author IBing
 * @Date 2022/8/5 15:11
 * @Version 1.0
 */
public class DeliveryDaoImpl implements DeliveryDao {
    @Override
    public List<Delivery> selectDelivery( Pager<DeliveryVO> pager) {
        String sql = "select did,uid,jid,rid,state from delivery";
        return SqlUtil.select(Delivery.class,sql);
    }

    @Override
    public List<Delivery> selectJobResume(Integer cid) {
        String sql = "select delivery.* from delivery where cid = ?";
        return SqlUtil.select(Delivery.class,sql,cid);
    }

    @Override
    public List<Delivery> selectJobResume(Integer cid, Integer state) {
        String sql = "select delivery.* from delivery where cid = ? and state = ?";
        return SqlUtil.select(Delivery.class,sql,cid,state);
    }

    @Override
    public int updateResumeState(Integer did, Integer state) {
        String sql = "update delivery set state=? where did=?";
        return SqlUtil.update(sql,state,did);
    }

    @Override
    public int updateResumeState(List didList, Integer state) {
        String sql = "update delivery set state=? where did=?";
        int count=0;
        for (int i = 0; i < didList.size(); i++) {
            SqlUtil.update(sql,state,didList.get(i));
            count++;
        }
        return count;
    }


    @Override
    public Resume selectResume(Integer rid) {
        String sql = "select rid,uid,path,filename, from resume  where rid=?";
        return SqlUtil.selectOne(Resume.class,sql,rid);
    }
    @Override
    public Resume selectResume(String uid) {
        String sql = "select resume.* from resume where uid = ?";
        return SqlUtil.selectOne(Resume.class,sql,uid);
    }


    @Override
    public User selectUser(String uid) {
        String sql = "select uid,username,nickname,sex,email,birthday,photo from user where uid=?";
        return SqlUtil.selectOne(User.class,sql,uid);
    }

    @Override
    public Company selectCompanyByUid(String uid) {
        String sql = "select company.* from company left join user_company on company.cid = user_company.cid where user_company.uid=?";
        return SqlUtil.selectOne(Company.class, sql, uid);
    }

    @Override
    public List<User> selectUserByNickname(String nickname) {
        String sql = "select user.* from user where nickname like ?";
        return SqlUtil.select(User.class,sql,nickname);
    }

    @Override
    public OnlineResume selectOnlineResume(String uid) {
        String sql = "select uid,advantage,expected_position,education,internship,min_salary,max_salary from online_resume  where uid=?";
        return SqlUtil.selectOne(OnlineResume.class,sql,uid);

    }
}
